
<%--
    Document   : loanRequest
    Created on : 04 14, 11, 15:27:20 PM
    Author     : MonicaSandoval
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib  prefix="s" uri="/struts-tags" %>
<%@taglib  prefix="sj" uri="/struts-jquery-tags" %>
<%@taglib  prefix="sjg" uri="/struts-jquery-grid-tags" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>


<div id="editrequest" style="width: 100%">
    <s:url id="remoteurl" action="editrequest" includeParams="all" ><s:param name="selected" value="%{#param.selected}"/></s:url>
    <s:url id="editurl" value="editloanapp" />
    <s:url id="loanappurl" value="loanprofile-loanapp.jsp" />
    <script type="text/javascript" src="<s:url value='/struts/js/base/jquery.ui.datepicker.min.js'/>"></script>
    <script type="text/javascript">
        $(document).ready(function(){
        <c:set var="selected" value="${param.selected}" scope="session" />
            });
            
            datePick = function(elem) {
                $(elem).datepicker();
                $("#ui-datepicker-div").css("z-index", 2000);
            }

            $.subscribe("gridCompleteTopics",function() {
                document.getElementById("selected").value = $("#gridtable").jqGrid("getDataIDs"); ;
            });

            $.subscribe('showcolumns', function(event,data) {
                $("#gridtable").jqGrid('setColumns',{});
            });

            function customFunc(value, colname){
                var date = new Date();
                var myDate = new Date(value);
                if(myDate <= date){
                    return [false, "Please enter a later date."];
                }else{
                    return [true, ""];
                }
            }

            function formatLink(cellvalue, options, rowObject) {
                return "<a href='<s:property value="loanappurl" />?id="+rowObject["loanverificationid"]+"' onClick='javascript: return openDialog(this)'>" + cellvalue + "</a>";
            }
            function openDialog(e) {
                window.open(e.href, "newWindow");
                return false;
            }
            function proceedButton(){
                document.savereq.submit();
            }
            function cancelButton(){
                $('#dialog').dialog('close');
            }
            function noButton(){
                $('#dialog1').dialog('close');
            }
    </script>
    <sjg:grid
        id="gridtable"
        caption="Edit Request"
        dataType="json"
        href="%{remoteurl}"
        pager="true"
        autowidth="true"
        navigator="true"
        gridModel="gridModel"
        rowList="10,15,20"
        rowNum="15"
        rownumbers="true"
        navigatorEditOptions="{height:280,reloadAfterSubmit:false}"
        cellEdit="true"
        cellurl="%{editurl}"
        sortable="false"
        shrinkToFit="false"
        onGridCompleteTopics="gridCompleteTopics"
        >

        <sjg:gridColumn name="loanverificationid"
                        index="loanverificationid"
                        title="Loan Verification No."
                        key="true"
                        hidedlg="true"
                        hidden="true"
                        />
        <sjg:gridColumn name="documentno" 
                        index="docno"
                        title="Document No."
                        formatter = "formatLink"
                        search="true"
                        align="center"
                        cssClass="gridlink"
                        />
        <sjg:gridColumn name="borrowername"
                        index="borrowername"
                        title="Borrower Name"
                        align="center"
                        />
        <sjg:gridColumn name="amountrequested"
                        index="amountrequested"
                        title="Promissory Note"
                        formatter="currency"
                        align="right"
                        editable="true"
                        edittype="text"
                        editrules="{
                        number:true,
                        required:true
                        }"
                        />
        <sjg:gridColumn name="areaname" 
                        index="area"
                        title="Area"
                        align="center"
                        />
        <sjg:gridColumn name="releasedate"
                        index="releasedate"
                        title="Specific Date of Release"
                        editable="true"
                        edittype="text"
                        editrules="{
                        date:true,
                        required:true,
                        custom:true,
                        custom_func:customFunc
                        }"
                        editoptions="{dataInit:datePick}"
                        formatoptions="{newformat:'m/d/Y'}"
                        align="center"
                        />
        <sjg:gridColumn name="borroweraddress"
                        index="raddress"
                        title="Residence Address"
                        align="center"
                        />
        <sjg:gridColumn name="businessaddresses"
                        index="baddress"
                        title="Business Address"
                        />
        <sjg:gridColumn name="businesstypes" 
                        index="btypes"
                        title="Business Type"
                        align="center"
                        />
        <sjg:gridColumn name="collaterals" 
                        index="collaterals"
                        title="Collaterals"
                        align="center"
                        />
        <sjg:gridColumn name="firstlast" 
                        index="firstlast"
                        title="Mode of Payment (1st Last)"
                        editable="true"
                        align="center"
                        edittype="text"
                        />
        <sjg:gridColumn name="secondlast"
                        index="secondlast"
                        title="Mode of Payment (2nd Last)"
                        editable="true"
                        align="center"
                        edittype="text"
                        />
        <sjg:gridColumn name="firstlastpn"
                        index="firstlastpn"
                        title="PN Amount (1st Last)"
                        formatter="currency"
                        align="right"
                        />
        <sjg:gridColumn name="secondlastpn" 
                        index="secondlastpn"
                        title="PN Amount (2nd Last)"
                        formatter="currency"
                        align="right" />
        <sjg:gridColumn name="creditmatrix.totalcreditrating" 
                        index="creditrating"
                        title="Credit Rating"
                        align="center" />
        <sjg:gridColumn name="auditor" 
                        index="empname"
                        title="Auditor Confirmation"
                        align="center"
                        />
    </sjg:grid>
    <br/>
    <div style="text-align:center">
        <sj:a
            name="showhide"
            id="showhide"
            button="true"
            buttonIcon="ui-icon-wrench"
            cssStyle="font-size:12px"
            onClickTopics="showcolumns"
            >
            Show/Hide Columns
        </sj:a>
    </div>
    <hr/>
    <sj:dialog
        id="dialog"
        autoOpen="false"
        modal="false"
        title="Save Request"
        >
        Are you sure you want to save the request?
        <br />        
        <s:form name="savereq" action="saverequest">
            <s:textfield name="selected" id="selected" value=""  cssStyle="display:none"/>
        </s:form>
        <sj:a
            name="yes"
            id="yes"
            button="true"
            cssStyle="font-size:12px"
            onclick="proceedButton()"
            >
            Yes
        </sj:a>
        <sj:a
            name="no"
            id="no"
            openDialog="dialog"
            button="true"
            cssStyle="font-size:12px"
            >
            No
        </sj:a>
        <sj:a
            name="cancel"
            id="cancel"
            button="true"
            cssStyle="font-size:12px"
            onclick="cancelButton()"
            >
            Cancel
        </sj:a>
    </sj:dialog>
    <sj:a
        name="createReq"
        id="createReq"
        openDialog="dialog"
        button="true"
        buttonIcon="ui-icon-disk"
        cssStyle="font-size:12px"
        >
        Save Loan Request
    </sj:a>

    <sj:dialog
        id="dialog1"
        autoOpen="false"
        modal="false"
        title="Exiting"
        >
        Are you sure you don't want to save the request?<br />
        <sj:a
            name="yes"
            id="yes"
            button="true"
            cssStyle="font-size:12px"
            href="/loanrequest.jsp?cat=request"
            >
            Yes
        </sj:a>
        <sj:a
            name="no2"
            id="no2"
            button="true"
            cssStyle="font-size:12px"
            onclick="noButton()"
            >
            No
        </sj:a>
    </sj:dialog>   
</div>
